/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.gov.mtc.dgac.licencias.persistence;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import pe.gov.mtc.dgac.licencias.bean.ClienteoperadorTO;
import pe.gov.mtc.dgac.licencias.bean.FuncionTO;
import pe.gov.mtc.dgac.licencias.bean.OperadorAereoTO;
import pe.gov.mtc.dgac.licencias.exception.TransactionException;

/**
 *
 * @author externo.gamaro
 */
public class ClienteoperadorImplDAO extends SqlMapClientTemplate implements ClienteoperadorDAO {
    Log logger = LogFactory.getLog(this.getClass());
    
    public List<ClienteoperadorTO> buscarClienteOperador(ClienteoperadorTO cliope) throws TransactionException {
        List<ClienteoperadorTO> list=null;
         
      try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
			
	  parmMap.put("pCodCliOper",cliope.getCodClieOper()); 
          parmMap.put("pCodCli",cliope.getCod_cliente()); 
          parmMap.put("pCodOperador",cliope.getOperadorAereo().getCodOperador()); 
                   
          queryForObject("ClienteOperador.buscarClienteOperador", parmMap);
          list=(List<ClienteoperadorTO>)parmMap.get("pResult");
          
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return list;
    }

    public List<OperadorAereoTO> buscarOperador(OperadorAereoTO ope) throws TransactionException {
        List<OperadorAereoTO> list=null;
         
      try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
			
	  parmMap.put("pCodOperador",ope.getCodOperador()); 
                   
          queryForObject("ClienteOperador.buscarOperador", parmMap);
          list=(List<OperadorAereoTO>)parmMap.get("pResult");
          
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return list;
    }

    public List<FuncionTO> buscarFuncion(FuncionTO func) throws TransactionException {
        List<FuncionTO> list=null;
         
      try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
			
	  parmMap.put("pCodFuncion",func.getCodFuncion()); 
                   
          queryForObject("ClienteOperador.buscarFuncion", parmMap);
          list=(List<FuncionTO>)parmMap.get("pResult");
          
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return list;
    }

    public HashMap insertClienteOperador(ClienteoperadorTO cliope) throws TransactionException {
        HashMap result=null;
        List list=null;
       try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
			
	  parmMap.put("pCodCli",cliope.getCod_cliente()); 
          parmMap.put("pCodOp",cliope.getOperadorAereo().getCodOperador()); 
          parmMap.put("pCodFuncion",cliope.getCodFuncion().getCodFuncion()); 
          parmMap.put("pFInicio",cliope.getSfechaInicio()); 
          parmMap.put("pFFin",cliope.getSfechaTermino()); 
                   
          queryForObject("ClienteOperador.insertarClienteOperador", parmMap);
          list=(List)parmMap.get("pResult");
          result=(HashMap)list.get(0);
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return result;
    }

    public HashMap deleteClienteOperador(ClienteoperadorTO cliope) throws TransactionException {
       HashMap result=null;
        List list=null;
       try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
			
	  parmMap.put("pSec",cliope.getCodClieOper()); 
          parmMap.put("pCodCli",cliope.getCod_cliente()); 
                           
          queryForObject("ClienteOperador.eliminarClienteOperador", parmMap);
          list=(List)parmMap.get("pResult");
          result=(HashMap)list.get(0);
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return result;
    }

    public HashMap updateClienteOperador(ClienteoperadorTO cliope) throws TransactionException {
        HashMap result=null;
        List list=null;
       try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
	  parmMap.put("pSec",cliope.getCodClieOper()); 		
	  parmMap.put("pCodCli",cliope.getCod_cliente()); 
          parmMap.put("pCodOp",cliope.getOperadorAereo().getCodOperador()); 
          parmMap.put("pCodFuncion",cliope.getCodFuncion().getCodFuncion()); 
          parmMap.put("pFInicio",cliope.getSfechaInicio()); 
          parmMap.put("pFFin",cliope.getSfechaTermino()); 
                   
          queryForObject("ClienteOperador.editarClienteOperador", parmMap);
          list=(List)parmMap.get("pResult");
          result=(HashMap)list.get(0);
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return result;
    }

}
